package com.example.demo2.service;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.demo2.common.Result;
import com.example.demo2.entity.AskKefu;
import com.example.demo2.entity.DTO.AskKefuDTO;
import com.example.demo2.mapper.AskKefuMapper;
import org.apache.logging.log4j.util.Strings;
import org.springframework.stereotype.Service;

@Service
public class AskKefuService extends ServiceImpl<AskKefuMapper, AskKefu> {

    public IPage<AskKefu> findPageOfCustomer(AskKefuDTO askKefuDTO) {
        LambdaQueryWrapper<AskKefu> lqw = new LambdaQueryWrapper<>();
        lqw.like(Strings.isNotEmpty(askKefuDTO.getContent()), AskKefu::getContent, askKefuDTO.getContent());
        lqw.like(Strings.isNotEmpty(askKefuDTO.getNickName()), AskKefu::getUserNickname, askKefuDTO.getNickName());
        lqw.orderByDesc(AskKefu::getCreateTime);
        Page<AskKefu> iPage = new Page<>(askKefuDTO.getPage(), askKefuDTO.getLimit());
        return page(iPage, lqw);
    }

    public Result removeByIdOfCustomer(Integer id) {
        boolean removeResult = removeById(id);
        if(removeResult){
            return Result.success("","删除成功",removeResult);
        }else {
            return Result.error("-1","删除失败");
        }
    }
}